<form class="form-inline" method="get">

    <div class="form-group col-xs-2">
        <select id="category-selector" name="cid" class="form-control" tabindex="-1">
            <option value="">
                无选择
            </option>
            {volist name="category_list" id="item"}
            <option value="{$item.id}" {if condition="$cid==$item.id"}selected{/if}>{$item.title}</option>
            {/volist}
        </select>
    </div>

    <div class="form-group col-xs-2">
        <div class="col-xs-12">
            <input class="form-control" name="condition" value="{$condition}"
                   placeholder="文章标题">
        </div>
    </div>
    <div class="form-group col-xs-2">
        <button type="submit" class="btn btn-success">
            搜索
        </button>

        <button type="button" class="btn btn-primary" onclick="modal('{:url(\'addArticle\')}','添加新闻')">
            添加新闻
        </button>
    </div>
</form>

<hr>

<table class="table table-striped">
    <thead>
    <tr>
        <td>ID</td>
        <td>新闻分类</td>
        <td>缩略图</td>
        <td>标题</td>
        <td>标签</td>
        <td>排序&浏览量</td>
        <td>编辑时间</td>
        <td>首页推荐</td>
        <td>显示</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {volist name="list" id="item"}
    <tr>
        <td>{$item.id}</td>
        <td>{$item.category_name}</td>
        <td>
            <a href="javascript:void(0);" onclick="ejectImg('{$item.thumb}','新闻【{$item.title}】缩略图');">
                <img style="width:100px;height:50px;" src="{$item.thumb}">
            </a>
        </td>
        <td>{$item.title}</td>
        <td>{$item.tag_id|get_article_tag}</td>
        <td>
            <p>排序：{$item.display_order}</p>
            <p>浏览：{$item.view_num}</p>
        </td>
        <td>{$item.update_time|show_datetime}</td>
        <td>
            <?php
                    $is_recommend_1 = '推荐';
                    $is_recommend_0 = '不推荐';
                ?>
            {if $item["is_recommend"]}
            <label class="label label-success" data-toggle="ajaxSwitch" data-switch-status="1" data-reload="true"
                   data-switch-value-0="1|{$is_recommend_1}|label label-success|{:url('recommendArticle',array('aid'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|{$is_recommend_0}|label label-danger|{:url('recommendArticle',array('aid'=>$item['id'],'status'=>0))}">{$is_recommend_1}</label>
            {else}
            <label class="label label-danger" data-toggle="ajaxSwitch" data-switch-status="0" data-reload="true"
                   data-switch-value-0="1|{$is_recommend_1}|label label-success|{:url('recommendArticle',array('aid'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|{$is_recommend_0}|label label-danger|{:url('recommendArticle',array('aid'=>$item['id'],'status'=>0))}">{$is_recommend_0}</label>
            {/if}
        </td>
        <td>
            {if condition="$item.is_visible == 1"}
            显示
            {else/}
            隐藏
            {/if}
        </td>
        <td>
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    操作
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="javascript:void(0)" onclick="modal('{:url(\'editArticle\',array(\'aid\'=>$item[\'id\']))}', '编辑新闻')">
                            编辑
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)" data-toggle="confirm"
                           data-title="删除新闻"
                           data-content="新闻将会被删除，确认删除？"
                           data-url="{:url('removeArticle',array('aid'=>$item['id']))}">
                            删除
                        </a>
                    </li>


                    <li role="separator" class="divider"></li>
                </ul>
            </div>
        </td>

    </tr>
    {/volist}
    </tbody>
</table>

<div class="row">
    <div class="col-xs-12" style="text-align: right;">
        {$list->render()}
    </div>
</div>

<script src="__PUBLIC__/vendors/select2/js/select2.min.js"></script>
<script type="application/javascript">
    $(function () {

        //获取分类
        $("#category-selector").select2({
            placeholder: "选择新闻分类",
            allowClear: true
        });
    });
</script>